package com.bhcj.telling.view.activity;

import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.viewpager2.widget.ViewPager2;

import com.bhcj.telling.R;
import com.bhcj.telling.view.adapter.MainAdapter;

public class MainActivity extends BaseActivity {

    private ViewPager2 viewPager;
    private RadioGroup radioGroup;
    private RadioButton divineBtn,diagramsBtn,jgBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        //初始化控件
        viewPager = findViewById(R.id.viewpager);
        radioGroup = findViewById(R.id.layout_tab);

        divineBtn = findViewById(R.id.divine);
        diagramsBtn = findViewById(R.id.diagrams);
        jgBtn = findViewById(R.id.jgBut);

        MainAdapter adapter = new MainAdapter(this);
        viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
            @Override
            public void onPageSelected(int position) {
                switch (position) {
                    case 0:
                        divineBtn.setChecked(true);
                        diagramsBtn.setChecked(false);
                        jgBtn.setChecked(false);
                        break;
                    case 1:
                        divineBtn.setChecked(false);
                        diagramsBtn.setChecked(true);
                        jgBtn.setChecked(false);
                        break;
                    case 2:
                        divineBtn.setChecked(false);
                        diagramsBtn.setChecked(false);
                        jgBtn.setChecked(true);
                        break;
                }
            }
        });
        //设置一个适配器
        viewPager.setAdapter(adapter);

        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                int id = group.getCheckedRadioButtonId();
                switch (id){
                    case R.id.divine:
                        viewPager.setCurrentItem(0);
                        break;
                    case R.id.diagrams:
                        viewPager.setCurrentItem(1);
                        break;
                    case R.id.jgBut:
                        viewPager.setCurrentItem(2);
                        break;

                }

            }
        });
    }

}